package com.hcy.rabbitruntimeapi;

import com.hcy.rabbitruntimeapi.center.CenterHandlerLink;
import com.hcy.rabbitruntimeapi.utils.ImportMyMessageHandler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;

import javax.annotation.PostConstruct;
import java.util.TimeZone;

/**
 * @Author huchenying
 * @Description
 * @Date 2021/12/15 13:27
 */
@SpringBootApplication(scanBasePackages = "com.hcy")
@EnableFeignClients(basePackages = "com.hcy")
@EnableDiscoveryClient
@EnableAsync
public class RuntimeApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(RuntimeApplication.class, args);

        //先拿出ioc容器中的 centerHandlerLink ，然后通过构造方法传入工具类
        //工具类通过扫描自定义注解 @MyMessageHandler ,将provider放入centerHandlerLink中
        //换aware接口注入,过时了
//        CenterHandlerLink centerHandlerLink = (CenterHandlerLink)run.getBean("centerHandlerLink");
//        ImportMyMessageHandler importMyMessageHandler = new ImportMyMessageHandler(run, centerHandlerLink);
//        importMyMessageHandler.run();
    }
    // 设置时区，防止new Date 时区不对
    @PostConstruct
    void started() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
    }
}
